<template>
	<div class="wrap">
		<div class="info" @click="login" v-if="token==0">
			<img class="arUrl" src="../../static/header-img.png" style="filter: grayscale(0.9);" alt="">
			<div class="nickname">登陆/注册</div>
		</div>

		<div class="info" v-else>
			<img class="arUrl login-bg" src="../../static/header-img.png" alt="">
			<div class="nickname">{{username}}</div>
		</div>

		<!-- <div class="flex">
			<div class="flex-item">
			</div>
		</div> -->
		<div class="list card-bg">
			<div class="list-item" v-for="(item,index) in list" :key="index" @tap.stop="deatail(item)">
				<image class="icon" :src="item.icon" mode="scaleToFill" alt=""></image>
				<div class="text">{{item.h}}</div>
				<img class="most" src="../../static/most.png" alt="">
				<!-- <div class="line" v-if="index != list.length-1"></div> -->
			</div>
		</div>
		<div class="list-btn card-bg" v-if="token!=0" @tap.stop="del()">退出登录</div>
		<div class="footerPo" style="z-index: 99;">
			<div class="liFoot cur" @tap.stop="tabbarClick('index')">
				<img src="../../static/sy2.png" class="liImg2" alt="">
				<div class="">首页</div>
			</div>
			<div style="color: #f0f0f0; line-height: 50px;">|</div>
			<div class="liFoot" @tap.stop="tabbarClick('my')">
				<img src="../../static/my.png" class="liImg" alt="">
				<div class="">我的</div>
			</div>
		</div>
		<image class="page-bg" src="../../static/page-bg.png" mode=""></image>
	</div>
</template>

<script>
	export default {
		components: {

		},
		data() {
			return {
				list: [{
						h: '我的收藏',
						text: 'collect',
						icon: '../../static/sc.png'
					},
					{
						h: '我的约看',
						text: 'reservation',
						icon: '../../static/yk.png'
					},
					{
						h: '我的合同',
						text: 'contract',
						icon: '../../static/yy.png'
					},
					{
						h: '我的服务',
						text: 'maintenance',
						icon: '../../static/yy.png'
					},
					// {
					// 	h: '开票管理',
					// 	text: 'invoice',
					// 	icon: '../../static/yy.png'
					// },
					// {
					// 	h: '我的企业',
					// 	text: 'enterprise',
					// 	icon: '../../static/yy.png'
					// },
					// {
					// 	h: '看房记录',
					// 	text: 'record',
					// 	icon: '../../static/kf.png'
					// },
					// {
					// 	h: '短租预定',
					// 	text: 'predetermine',
					// 	icon: '../../static/yy.png'
					// },
					{
						h: '退房管理',
						text: 'handle',
						icon: '../../static/yy.png'
					},
					{
						h: '工单管理',
						text: 'work',
						icon: '../../static/yy.png'
					},
					{
						h: '工单代办',
						text: 'backlog',
						icon: '../../static/yy.png'
					},
					{
						h: '隐私管理',
						text: 'privacy',
						icon: '../../static/sz.png'
					},
				],

				token: 0,
				username: uni.getStorageSync('phone')
			}
		},
		onLoad(option) {},
		onShow() {
			if (uni.getStorageSync('openId')) {
				this.token = 1
				let data = {
					openId: uni.getStorageSync('openId')
				}

				this.api.get('hetong/refund/app/selPostCodeApp', data).then(res => {
					uni.setStorageSync('user', res.data.postCode)
					uni.setStorageSync('userDeptId', res.data.userDeptId)
				})
			}

			if (uni.getStorageSync('permission') == 0) {
				for (let i = 0; i < this.list.length; i++) {
					if (this.list[i].text == 'handle') {
						this.list.splice(i, 1)
					}
				}
			}

			if (uni.getStorageSync('openId') == '' || uni.getStorageSync('openId') == null || uni.getStorageSync(
					'openId') == undefined) {
				for (let i = 0; i < this.list.length; i++) {
					if (this.list[i].text == 'maintenance') {
						this.list.splice(i, 1)
					}
				}
			}
		},
		onShareAppMessage(res) { //发送给朋友
			return {
				title: '逸居盛京',
				path: '/pages/home/index',
				imageUrl: "",
			}
		},
		onShareTimeline(res) { //分享到朋友圈
			return {
				title: '逸居盛京',
				path: '/pages/home/index',
				imageUrl: "",
			}
		},
		methods: {
			tabbarClick(e) {
				if (e == 'index') {
					uni.reLaunch({
						url: '/pages/home/' + e
					})
				} else {
					uni.reLaunch({
						url: '/pages/' + e + '/' + e
					})
				}
			},

			del() {
				uni.clearStorage()
				uni.setStorageSync('permission', 0)
				this.token = 0
				if (uni.getStorageSync('permission') == 0) {
					for (let i = 0; i < this.list.length; i++) {
						if (this.list[i].text == 'handle') {
							this.list.splice(i, 1)
						}
					}
				}
				if (uni.getStorageSync('openId') == '' || uni.getStorageSync('openId') == null || uni.getStorageSync(
						'openId') == undefined) {
					for (let i = 0; i < this.list.length; i++) {
						if (this.list[i].text == 'maintenance') {
							this.list.splice(i, 1)
						}
					}
				}
			},

			login() {
				uni.reLaunch({
					url: "/pages/login/login"
				})
			},

			deatail(e) {
				// console.log(e)
				if (e.text == 'collect' ||
					e.text == 'reservation' ||
					e.text == 'order' ||
					e.text == 'invoice' ||
					e.text == 'contract' ||
					e.text == 'handle' ||
					e.text == 'maintenance' ||
					e.text == 'work' ||
					e.text == 'backlog') {
					uni.navigateTo({
						url: "/pages/my/" + e.text
					})
				} else {
					uni.showToast({
						title: '暂未开放',
						icon: 'none',
						duration: 1500
					});
				}

			}
		}
	}
</script>

<style>
	@import '/common/css/my/my.scss';
</style>

<style lang="scss">

</style>